/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2024-05-12     liuchao       the first version
 */
#include "drv_btn.h"
#include "drv_relay.h"

btn_state_e btn_state(btn_e btn)
{
    btn_state_e ret = BTN_STATE_INACTIVE;
    switch (btn)
    {
    case BTN_AUTO:
        if (rt_pin_read(BTN_AUTO_MODE_PIN) == PIN_LOW)
        {
            ret = BTN_STATE_ACTIVE;
        }
        break;
    case BTN_MANUAL:
        if (rt_pin_read(BTN_MANUAL_MODE_PIN) == PIN_LOW)
        {
            ret = BTN_STATE_ACTIVE;
        }
        break;
    case BTN_PUSH:
        if (rt_pin_read(BTN_PUSH_PIN) == PIN_LOW)
        {
            ret = BTN_STATE_ACTIVE;
        }
        break;
    case BTN_BACK:
        if (rt_pin_read(BTN_BACK_PIN) == PIN_LOW)
        {
            ret = BTN_STATE_ACTIVE;
        }
        break;
    }

    return ret;
}

static int btn_mode_init()
{
    rt_pin_mode(MODE_ON_PIN, PIN_MODE_OUTPUT);
    rt_pin_write(MODE_ON_PIN, PIN_HIGH);

    rt_pin_mode(BTN_STOP_MODE_PIN, PIN_MODE_INPUT);
    rt_pin_mode(BTN_MONITOR_MODE_PIN, PIN_MODE_INPUT);
    rt_pin_mode(BTN_MANUAL_MODE_PIN, PIN_MODE_INPUT);
    rt_pin_mode(BTN_AUTO_MODE_PIN, PIN_MODE_INPUT);

    return RT_EOK;
}
INIT_COMPONENT_EXPORT(btn_mode_init);
